package cn.edu.nju.gitlab.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.text.DecimalFormat;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

import cn.edu.nju.gitlab.R;
import cn.edu.nju.gitlab.injector.DaggerActivityComponent;
import cn.edu.nju.gitlab.injector.MainModule;
import cn.edu.nju.gitlab.presenter.ScorePresenter;

/**
 * Created by tjDu on 2017/6/13.
 */

public class ScoreFragment extends Fragment {

    protected String username;
    protected String password;
    private int assignmentId;
    public double[] datas;

    @BindView(R.id.data1)
    TextView data1;
    @BindView(R.id.data2)
    TextView data2;
    @BindView(R.id.data3)
    TextView data3;
    @BindView(R.id.data4)
    TextView data4;
    @BindView(R.id.data5)
    TextView data5;
    @BindView(R.id.data6)
    TextView data6;
    @Inject
    ScorePresenter presenter;

    public void setUserInfo(String username, String password, int assignmentId) {
        this.username = username;
        this.password = password;
        this.assignmentId = assignmentId;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.score, container, false);
        ButterKnife.bind(this, view);
        DaggerActivityComponent.builder()
                .mainModule(new MainModule(this))
                .build()
                .inject(this);
        presenter.getLineChartData(username, password, assignmentId);
        return view;
    }


    public void showError() {

    }


    public void showLineChart(double[] data) {
        datas=data;
        data1.setText(""+(int)data[0]);
        data2.setText(""+(int)data[1]);
        data3.setText(""+(int)data[2]);
        data4.setText(""+(int)data[3]);
        data5.setText(""+(int)data[4]);
        DecimalFormat df = new DecimalFormat("0.00");

        data6.setText(""+df.format(data[5]));

    }
    public double[]  getData(){
        return datas;
    }
}
